package main

import (
	"fmt"
	"mmo/api"
	"mmo/core"
	"mmo/event"
	"mmo/message"
	"os"
	"os/signal"
	"syscall"
	"zinxtcp/server"
)

func main() {
	signChannel := make(chan os.Signal, 1)
	signal.Notify(signChannel, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)

	//创建服务器句柄
	s := server.NewServer1("conf/binx.json")
	s.SetConnEvent(&event.ConnEvent{})
	//注册客户端连接建立和丢失函数

	//注册路由
	s.AddRouter(2, &api.WorldChatApi{})
	s.AddRouter(3, &api.MoveApi{})

	s.SetEncoder(&message.Encoder{})

	//启动服务
	err := s.Serve()

	if err != nil {
		goto EXIT
	}
	for {
		select {
		case <-signChannel:
			fmt.Println("Get shutdown sign")
			fmt.Println(core.WorldMgrObj.GetAllPlayers())
			fmt.Println(core.WorldMgrObj.AoiMgr)

			goto EXIT
		}
	}

EXIT:
	s.Stop()
	fmt.Println("main Server shutdown 6666666666666666666666666")
}
